//
//  CSEditView.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/10/31.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSEditView.h"
#import "CSTextField.h"

@interface CSEditView ()
@property (weak, nonatomic) UILabel *lblTitle;
@property (weak, nonatomic) CSTextField *txtEdit;

@end

@implementation CSEditView

+ (instancetype)editView {
    return [[self alloc] init];
}

+ (instancetype)editViewWithDict:(NSDictionary *)dict {
    id obj = [self editView];
    ((CSEditView *)obj).editViewDict = dict;
    return obj;
}

#pragma markl - setupUI
-(void) setupUI {
//    self.backgroundColor = kColorBar;
    //
    UILabel * lblTitle = [UILabel gx_labelWithText:@"title" fontSize:16 color:nil];
    [self addSubview:lblTitle];
    
    [lblTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.bottom.equalTo(self);
    }];
    
    [lblTitle sizeToFit];
    
    //
    CSTextField * txtEdit = [CSTextField gx_textFieldWithLineColor:[UIColor gx_colorWithRed:232 green:232 blue:232] lineWidth:3];
    [self addSubview:txtEdit];
    
    [txtEdit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(lblTitle);
        make.leading.equalTo(lblTitle.mas_trailing).offset(2);
        make.width.mas_greaterThanOrEqualTo(50);
    }];
    
    //
    self.lblTitle = lblTitle;
    self.txtEdit = txtEdit;
}

#pragma mark - setter & getter

- (void)setEditViewDict:(NSDictionary *)editViewDict {
    _editViewDict = editViewDict;
    
    self.fontSize = [editViewDict[@"fontSize"] floatValue];
    self.lblTitle.text = editViewDict[@"title"];
    self.txtEdit.text = editViewDict[@"edit"];
}


- (void)setLineColor:(UIColor *)lineColor {
    _lineColor = lineColor;
    self.txtEdit.lineColor = lineColor;
}

- (void)setFontSize:(CGFloat)fontSize {
    _fontSize = fontSize;
    
    self.lblTitle.font = self.txtEdit.font = [UIFont systemFontOfSize:fontSize];
}

@end
